package thread.Test;

//ThreadTest.java 源码
class MyThread extends Thread {
	private int ticket = 10;

	public void run() {
		for (int i = 0; i < 20; i++) {
			if (this.ticket > 0) {
				System.out.println(this.getName() + " 卖票：ticket"
						+ this.ticket--);
			}
		}
	}
}

public class ThreadTest {
	public static void main(String[] args) {
		// 启动3个线程t1,t2,t3；每个线程各卖10张票！
		MyThread t1 = new MyThread();
		MyThread t2 = new MyThread();
		MyThread t3 = new MyThread();
		t1.start();
		t2.start();
		t3.start();
	}
};

/*
 * 每次运行 Thread 运行顺序不定
Thread-1 卖票：ticket10
Thread-1 卖票：ticket9
Thread-1 卖票：ticket8
Thread-1 卖票：ticket7
Thread-1 卖票：ticket6
Thread-1 卖票：ticket5
Thread-1 卖票：ticket4
Thread-1 卖票：ticket3
Thread-1 卖票：ticket2
Thread-1 卖票：ticket1
Thread-0 卖票：ticket10
Thread-0 卖票：ticket9
Thread-0 卖票：ticket8
Thread-0 卖票：ticket7
Thread-0 卖票：ticket6
Thread-0 卖票：ticket5
Thread-0 卖票：ticket4
Thread-0 卖票：ticket3
Thread-0 卖票：ticket2
Thread-0 卖票：ticket1
Thread-2 卖票：ticket10
Thread-2 卖票：ticket9
Thread-2 卖票：ticket8
Thread-2 卖票：ticket7
Thread-2 卖票：ticket6
Thread-2 卖票：ticket5
Thread-2 卖票：ticket4
Thread-2 卖票：ticket3
Thread-2 卖票：ticket2
Thread-2 卖票：ticket1

 * 
 * */
